| Conditions | 1 |
| Paths | 1 |
| Total Lines | 147 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| Bugs | 3 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai'); |
||
| 13 | describe('Request', function() { |
||
| 14 | before( function(done) { |
||
| 15 | Manager.instance.init() |
||
| 16 | .then(function () { |
||
| 17 | this.fixture = { |
||
| 18 | tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'), |
||
| 19 | json: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json') |
||
| 20 | } |
||
| 21 | done() |
||
| 22 | |||
| 23 | }.bind(this)) |
||
| 24 | }); |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Sql.getAllAttributes |
||
| 28 | * |
||
| 29 | */ |
||
| 30 | it('Util.getAllAttributes()', function(done) { |
||
| 31 | var attributes = Util.getAllAttributes(this.fixture.tag, this.fixture.json) |
||
| 32 | chai.expect(attributes.sourceString).to.contain('select'); |
||
| 33 | done(); |
||
| 34 | }); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Sql.executeQuery |
||
| 38 | * |
||
| 39 | */ |
||
| 40 | it('Sql.executeQuery()', function(done) { |
||
| 41 | try { |
||
| 42 | var match = 'select * from ../' |
||
| 43 | var jsonPage = {} |
||
| 44 | var res = Sql.handleSqlRequest(match, {}) |
||
| 45 | |||
| 46 | chai.assert.equal(res.string, 'select ["*"] from ["___abe_dot______abe_dot______abe___"] ', 'select not well formatted') |
||
| 47 | done(); |
||
| 48 | } catch (x) { |
||
| 49 | done(x); |
||
| 50 | } |
||
| 51 | }); |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Sql.executeFromClause |
||
| 55 | * |
||
| 56 | */ |
||
| 57 | it('Sql.executeFromClause()', function() { |
||
| 58 | var res = Sql.executeFromClause(['/'], ['/']) |
||
| 59 | chai.expect(res).to.have.length(2); |
||
| 60 | }); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Sql.whereEquals |
||
| 64 | * |
||
| 65 | */ |
||
| 66 | it('Sql.executeWhereClause() >', function() { |
||
| 67 | var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`>`1`', {}) |
||
| 68 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 69 | chai.expect(res).to.have.length(1); |
||
| 70 | }); |
||
| 71 | it('Sql.executeWhereClause() >=', function() { |
||
| 72 | var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`>=`1`', {}) |
||
| 73 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 74 | chai.expect(res).to.have.length(2); |
||
| 75 | }); |
||
| 76 | it('Sql.executeWhereClause() <', function() { |
||
| 77 | var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`<`1`', {}) |
||
| 78 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 79 | chai.expect(res).to.have.length(0); |
||
| 80 | }); |
||
| 81 | it('Sql.executeWhereClause() <=', function() { |
||
| 82 | var request = Sql.handleSqlRequest('select title from ./ where `abe_meta.priority`<=`1`', {}) |
||
| 83 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 84 | chai.expect(res).to.have.length(1); |
||
| 85 | }); |
||
| 86 | it('Sql.executeWhereClause() =', function() { |
||
| 87 | var request = Sql.handleSqlRequest('select title from ./ where template=`article`', {}) |
||
| 88 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 89 | chai.expect(res).to.have.length(1); |
||
| 90 | }); |
||
| 91 | it('Sql.executeWhereClause() !=', function() { |
||
| 92 | var request = Sql.handleSqlRequest('select title from ./ where template!=`homepage`', {}) |
||
| 93 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 94 | chai.expect(res).to.have.length(1); |
||
| 95 | }); |
||
| 96 | it('Sql.executeWhereClause() LIKE', function() { |
||
| 97 | var request = Sql.handleSqlRequest('select title from ./ where template LIKE `home`', {}) |
||
| 98 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 99 | chai.expect(res).to.have.length(1); |
||
| 100 | }); |
||
| 101 | it('Sql.executeWhereClause() NOT LIKE', function() { |
||
| 102 | var request = Sql.handleSqlRequest('select title from ./ where template NOT LIKE `home`', {}) |
||
| 103 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 104 | chai.expect(res).to.have.length(1); |
||
| 105 | }); |
||
| 106 | it('Sql.executeWhereClause() AND', function() { |
||
| 107 | var request = Sql.handleSqlRequest('select title from ./ where template=`homepage` AND title=`homepage`', {}) |
||
| 108 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 109 | chai.expect(res).to.have.length(1); |
||
| 110 | }); |
||
| 111 | it('Sql.executeWhereClause() OR', function() { |
||
| 112 | var request = Sql.handleSqlRequest('select title from ./ where template=`homepage` OR template=`article`', {}) |
||
| 113 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 114 | chai.expect(res).to.have.length(2); |
||
| 115 | }); |
||
| 116 | it('Sql.executeWhereClause() IN', function() { |
||
| 117 | var request = Sql.handleSqlRequest('select title from ./ where template IN (`homepage`,`test`) AND title=`homepage`', {}) |
||
| 118 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 119 | chai.expect(res).to.have.length(1); |
||
| 120 | }); |
||
| 121 | it('Sql.executeWhereClause() NOT IN', function() { |
||
| 122 | var request = Sql.handleSqlRequest('select title from ./ where template NOT IN (`homepage`,`test`)', {}) |
||
| 123 | var res = Sql.executeWhereClause(Manager.instance.getList(), request.where, request.limit, request.columns, {}) |
||
| 124 | chai.expect(res).to.have.length(1); |
||
| 125 | }); |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Sql.whereLike |
||
| 129 | * |
||
| 130 | */ |
||
| 131 | it('Sql.getSourceType()', function() { |
||
| 132 | chai.expect(Sql.getSourceType('http://google.com')).to.equal('url'); |
||
| 133 | chai.expect(Sql.getSourceType('select * from test')).to.equal('request'); |
||
| 134 | chai.expect(Sql.getSourceType('{"test":"test"}')).to.equal('value'); |
||
| 135 | chai.expect(Sql.getSourceType('references.json')).to.equal('file'); |
||
| 136 | chai.expect(Sql.getSourceType('test')).to.equal('other'); |
||
| 137 | }); |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Sql.requestList |
||
| 141 | * |
||
| 142 | */ |
||
| 143 | it('Sql.requestList()', function(done) { |
||
| 144 | let util = new Util() |
||
| 145 | var matches = util.dataRequest(this.fixture.tag) |
||
| 146 | |||
| 147 | chai.expect(matches[0][0]).to.not.be.null |
||
| 148 | |||
| 149 | var attributes = Util.getAllAttributes(matches[0][0], {}) |
||
| 150 | chai.expect(matches[0][0]).to.not.be.null |
||
| 151 | |||
| 152 | var jsonPage = {} |
||
| 153 | Util.requestList(attributes, '', matches[0][0], jsonPage) |
||
| 154 | .then(function () { |
||
| 155 | chai.expect(jsonPage.abe_source).to.not.be.undefined |
||
| 156 | done() |
||
| 157 | }) |
||
| 158 | }); |
||
| 159 | }); |
||
| 160 |